package ${serviceImpl.packagePath};

<#list serviceImpl.packages as pkg>
<#if pkg?has_content>
import ${pkg};
<#else>

</#if>
</#list>

/**
 * <p>
 * ${tableComment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
public class ${serviceImpl.className} extends StandardServiceImpl<${mapper.className}, ${entity.className}> implements ${service.className} {
    <#if genPage>

    @Override
    public IPage<${pageResult.className}> page(${pageParam.className} param) {
        return this.page(PageQueryUtils.getPage(param), getQueryWrapper(param)).convert(${pageResult.className}::of);
    }
    </#if>
    <#if genPage || genExport>

    private LambdaQueryWrapper<${entity.className}> getQueryWrapper(${pageParam.className} param) {
        return lambdaQueryWrapper()
        <#list fieldInfoList as field>
            <#if field.showInQuery && field.queryType??>
                <#if field.queryType.mpType="between">
                .between(ObjectUtil.isNotEmpty(param.get${field.fieldName?cap_first}Start()) && ObjectUtil.isNotEmpty(param.get${field.fieldName?cap_first}End()),
                        ${entity.className}::get${field.fieldName?cap_first},
                        param.get${field.fieldName?cap_first}Start(), param.get${field.fieldName?cap_first}End())
                <#else>
                .${field.queryType.mpType}(ObjectUtil.isNotEmpty(param.get${field.fieldName?cap_first}()), ${entity.className}::get${field.fieldName?cap_first}, param.get${field.fieldName?cap_first}())
                </#if>
            </#if>
        </#list>
                .orderByDesc(CollUtil.isEmpty(param.getSortList()), ${entity.className}::getId);
    }
    </#if>
    <#if genInfo>

    @Override
    public ${infoResult.className} info(${pkType} id) {
        if (id == null) {
            return null;
        }
        return ${infoResult.className}.of(this.getById(id));
    }
    </#if>
    <#if genSave>

    @Override
    public void save(${saveParam.className} param) {
        ${entity.className} entity = param.toEntity();
        this.save(entity);
    }
    </#if>
    <#if genUpdate>

    @Override
    public void update(${updateParam.className} param) {
        ${entity.className} entity = param.toEntity();
        this.updateById(entity);
    }
    </#if>
    <#if genDeleted>

    @Override
    public void delete(List<${pkType}> ids) {
        if (CollUtil.isEmpty(ids)) {
            return;
        }
        this.removeByIds(ids);
    }
    </#if>
    <#if genImport>

    @Override
    public void importExcel(InputStream in) {
        List<${importParam.className}> paramList = ExcelUtil.readExcel(in, ${importParam.className}.class);
        List<${entity.className}> saveList = paramList.stream().map(${importParam.className}::toEntity).toList();
        this.insertBatchSomeColumn(saveList);
    }

    @Override
    public void importExcelTemplate(OutputStream out) {
        ExcelUtil.writeExcel(out, new ExcelSheet<>(Collections.emptyList(), ${importParam.className}.class));
    }
    </#if>
    <#if genExport>

    @Override
    public void exportExcel(${pageParam.className} param, OutputStream out) {
        List<${entity.className}> dataList = this.list(getQueryWrapper(param));
        List<${exportResult.className}> exportList = dataList.stream().map(${exportResult.className}::of).toList();
        ExcelUtil.writeExcel(out, new ExcelSheet<>(exportList, ${exportResult.className}.class));
    }
    </#if>
}
